package com.webapp.org.runner;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.context.ApplicationContext;

import com.webapp.org.bean.CategoryBean;
import com.webapp.org.bean.DepartmentBean;
import com.webapp.org.bean.DesignationBean;
import com.webapp.org.bean.QualifiedTestBean;
import com.webapp.org.bean.ResultDateBean;
import com.webapp.org.dao.ResultDateDAO;
import com.webapp.org.service.CategoryService;
import com.webapp.org.service.DepartmentService;
import com.webapp.org.service.DesignationService;
import com.webapp.org.service.QualifiedTestService;

@SuppressWarnings("unused")
public class RunnerProgram {

	public void category( )
	{

		CategoryBean incategoryBean = new CategoryBean();
		incategoryBean.setCategoryName("Open");
		incategoryBean.setRemark("Open catgeroy");

		CategoryService categoryService = new CategoryService();
		//CategoryService categoryService = (CategoryService) context.getBean("categoryService");
		
		boolean result = categoryService.insertCategory(incategoryBean);
		System.out.println("insert result is " + result);

		CategoryBean upcategoryBean = new CategoryBean();
		upcategoryBean.setCategoryID(1);
		upcategoryBean.setRemark("OBC catgeroy");

		result = categoryService.updateCategory(upcategoryBean);
		System.out.println("update result is " + result);

		System.out.println(categoryService.retrieveCategory().toString());

		result = categoryService.deleteCategory(3);
		System.out.println("delete result is " + result);
	}

	public void department()
	{
		DepartmentBean departmentBean = new DepartmentBean();
		departmentBean.setDepartmentName("development");
		departmentBean.setRemark("Software development");

		DepartmentService DepartmentService = new DepartmentService();
		boolean result = DepartmentService.insertDepartment(departmentBean);
		System.out.println("insert result is " + result);

		DepartmentBean upDepartmentBean = new DepartmentBean();
		upDepartmentBean.setDeptId(4);
		upDepartmentBean.setRemark("OBC catgeroy");

		result = DepartmentService.updateDepartment(upDepartmentBean);
		System.out.println("update result is " + result);

		System.out.println(DepartmentService.retrieveDepartment().toString());

		result = DepartmentService.deleteDepartment(3);
		System.out.println("delete result is " + result);

	}

	public void designation()
	{
		DepartmentBean departmentbean = new DepartmentBean();
		// departmentbean.setDepartmentName("1");
		departmentbean.setDeptId(1);

		DesignationBean designationBean = new DesignationBean();
		designationBean.setDesgName("manager");
		designationBean.setDepartmentBean(departmentbean);

		DesignationService designationService = new DesignationService();

		boolean result = designationService.insertDesignation(designationBean);
		System.out.println(result);

		designationBean.setDesgName("software");
		designationBean.setDesgId(2);
		result = designationService.updateDesignation(designationBean);
		System.out.println(result);

		designationBean.setDesgId(3);

		List<DesignationBean> li = designationService.retrieveDesignation();
		System.out.println(li.toString());

		designationBean.setDesgId(2);
		result = designationService.deleteDesignation(designationBean
				.getDesgId());
		System.out.println(result);

	}

	public void getQualifiedTest()
	{
		QualifiedTestService qualifiedTestService = new QualifiedTestService();
		CategoryBean categoryBean = new CategoryBean();
		categoryBean.setCategoryID(1);

		QualifiedTestBean qualifiedTestBean = new QualifiedTestBean();
		qualifiedTestBean.setQualifiedTestName("Degree");
		qualifiedTestBean.setCategoryBean(categoryBean);

		boolean result = qualifiedTestService
				.insertQualifiedTest(qualifiedTestBean);
		System.out.println("QT insert " + result);

		qualifiedTestBean.setQualifiedTestId(1);
		result = qualifiedTestService.updateQualifiedTest(qualifiedTestBean);
		System.out.println("Qt update " + result);

		List<QualifiedTestBean> qualifiedList = qualifiedTestService
				.retrieveQualifiedTest();
		System.out.println(qualifiedList.toString());

		QualifiedTestBean qualifiedTestBean2 = qualifiedTestService
				.getQualifiedTest(1);
		System.out.println(qualifiedTestBean2.toString());

		result = qualifiedTestService.deleteQualifiedTest(1);
		System.out.println("qt deleted" + result);

	}

	public void runable()
	{
		// For passing Date of birth as String
		SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
		Date dob = null;
		try
		{
			dob = sdf.parse("21-05-1988");
		} catch (ParseException e)
		{
			e.printStackTrace();
		}
		ResultDateBean resultDateBean = new ResultDateBean();
		resultDateBean.setRemark("Hello");
		resultDateBean.setResultDate(dob);

		boolean result = new ResultDateDAO().insertResultDate(resultDateBean);
		System.out.println(result);
	}
	public static void main(String[] args) {
		new RunnerProgram().department();
	}

}
